using System;
using System.Web.UI;
using Eneta.Portal.Forum.Controls.Base;
using Eneta.Portal.Forum.Core.Domain.Collections;
using Eneta.Portal.Forum.Core.Service.Application;

namespace Eneta.Portal.Forum.Controls
{
    public class ShowToday : BaseForumControl
    {
        protected override void CreateChildControls()
        {
            Controls.Add(BuildPageLinks("Todays Topics", ""));
            TopicCollection topics = RepositoryRegistry.TopicRepository.FindByDate(DateTime.Now);

            StartTopicTable();
            DisplayTopics(topics);
            EndTopicTable();
        }	

        private void StartTopicTable()
        {
            Controls.Add(new LiteralControl("<table width=100% cellspacing=1 cellpadding=3>"));
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl(string.Format("<td colspan=6 class=\"ms-ToolPaneTitle\">{0}</td>", "Todays Topics")));
            Controls.Add(new LiteralControl("</tr>"));
            Controls.Add(new LiteralControl("<tr>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" width=1%>&nbsp;</td>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" align=left><strong>Topics</strong></td>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" align=middle width=7%><strong>Replies</strong></td>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" align=middle width=20%><strong>Author</strong></td>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" align=middle width=7%><strong>Views</strong></td>"));
            Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" align=middle width=25%><strong>Last Post</strong></td>"));
            Controls.Add(new LiteralControl("</tr>"));
        }

        private void EndTopicTable()
        {
            Controls.Add(new LiteralControl("</table>"));
        }
    }
}